/**********************************************************************\

 Copyright 2012 Diggory Blake

 This file is part of klip-engine

 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.

\**********************************************************************/
#pragma once

class kLine;
class kEngine;
class kMaterial;

#include "kmesh2d.h"
#include "kimage.h"
#include "kblend.h"

class kLine : public kMesh2DBase {
private:
	kVec2 _a, _b;
	float _width;

	void updateMesh();
public:
	kLine(kEngine* engine);
	~kLine();

	inline void setColor(const kColor& diffuse) {
		for (size_t i = 0; i < 4; i++)
			kMesh2DBase::setColor(i, diffuse);
	}
	inline void setColor(const kColor& a, const kColor& b) {
		kMesh2DBase::setColor(0, a);
		kMesh2DBase::setColor(1, a);
		kMesh2DBase::setColor(2, b);
		kMesh2DBase::setColor(3, b);
	}
	inline const kColor& getColorA() const {
		return getColor(0);
	}
	inline const kColor& getColorB() const {
		return getColor(2);
	}
	inline void setAB(const kVec2& a, const kVec2& b) {
		_a = a;
		_b = b;

		updateMesh();
	}
	inline void setPolar(const kVec2& a, float angle, float length) {
		_a = a;
		_b = _a + kVec2(cos(angle), sin(angle))*length;

		updateMesh();
	}
	inline void setWidth(float width) {
		_width = width;

		updateMesh();
	}
	inline float getWidth() const {
		return _width;
	}
	inline const kVec2& getA() const {
		return _a;
	}
	inline const kVec2& getB() const {
		return _b;
	}
	inline void setPatternRepeat(float repeat) {
		setTextureCoord(2, kVec2(repeat, 0.0f));
		setTextureCoord(3, kVec2(repeat, 1.0f));
	}
	inline float getLength() const {
		return length(_b-_a);
	}
	inline float getAngle() const {
		return atan2(_b.y-_a.y, _b.x-_a.x);
	}
};
